WorkflowTest<'Input, 'Result>Type

PackageFCQRS.Workflows
A workflow instance run in memory, for tests. It stores the records the workflow actor would store, without an actor system or a database. Activities, commands, and child workflows do not run: the test gives each step's outcome with `Complete` or `Fail`. Time moves only with `Advance`, which fires timers and signal timeouts. Retry policies are not applied: the outcome a test gives is the step's final one. Start one with `WorkflowTest.Start`.

Specification

Kind
Type
Members
19
Examples
0
AdvanceSignature
this.Advance
CancelSignature
this.Cancel
CheckReplaySignature
this.CheckReplay
CompleteSignature
this.Complete
FailSignature
this.Fail

Summary

NameSignatureSynopsis
Advancethis.AdvanceMoves the time forward, and fires the timers and signal timeouts that are due by then.
Cancelthis.CancelCancels the instance: every waiting step fails as `Cancelled`, and the body can run its cleanup.
CheckReplaythis.CheckReplayRestarts the instance after every stored record the test produced, gives it the same outcomes, and checks that each restart stores the same journal.
Completethis.CompleteCompletes the waiting activity, command, or child step named `step` with `value`, which is stored and read back as the actor does.
Failthis.FailFails the waiting step named `step` as its retry policy's attempts running out (`Exhausted`).
Failthis.FailFails the waiting activity, command, or child step named `step` with `kind`.
Restartthis.RestartReplays the journal into a new run of the body, as the process does after it stops.
Resumethis.ResumeResumes a faulted instance at the step whose failure faulted it, as `Resume` does for a registered workflow: the body replays its stored steps and that step waits again for the test's outcome.
Signalthis.SignalStores a signal, as `Workflows.signal` does.
StartAgainthis.StartAgainStarts a new run with `input`, as a start with `WorkflowIdReuse.AfterFailure` does: only when the instance faulted or was cancelled.
Summarythis.SummaryOne line per stored record, such as `"scheduled 0 price"` or `"completed 0 price"`: the step's path and name.
Waitingthis.WaitingThe steps the body waits on, in the order they started.
Outcomethis.OutcomeHow the instance ended, or `None` while it runs or is parked.
Nowthis.NowThe time the test runs at.
Statusthis.StatusWhere the instance is, as `Status` reports it for a registered workflow.
Idthis.IdThe instance's ID, `test`.
Journalthis.JournalEvery record the instance stored, in journal order.
Resultthis.ResultThe body's result.
Namethis.NameThe workflow's name.

Advance

this.Advance
Member
Moves the time forward, and fires the timers and signal timeouts that are due by then.

Parameters

NameTypeDescription
byTimeSpan

Returns

unit

Cancel

this.Cancel
Member
Cancels the instance: every waiting step fails as `Cancelled`, and the body can run its cleanup. An instance that has ended is left as it is.

Returns

unit

CheckReplay

this.CheckReplay
Member
Restarts the instance after every stored record the test produced, gives it the same outcomes, and checks that each restart stores the same journal. Raises `WorkflowReplayException` for the first restart that stores a different record or parks the instance: a body whose steps, stored values, or result change on replay. A pass does not show that the body is deterministic: an activity's arguments are not stored, so a GUID or a time read outside a step that reaches only an activity's call is not seen.

Returns

unit

Complete

this.Complete
Member
Completes the waiting activity, command, or child step named `step` with `value`, which is stored and read back as the actor does. A value the step cannot read back fails the step as `NotRetryable`. Raises `InvalidOperationException` when no such step waits, and `ArgumentException` when `value` cannot be stored as the step's result.

Parameters

NameTypeDescription
stepstring
value'T

Returns

unit

Fail

this.Fail
Member
Fails the waiting step named `step` as its retry policy's attempts running out (`Exhausted`).

Parameters

NameTypeDescription
stepstring
errorexn

Returns

unit

Fail

this.Fail
Member
Fails the waiting activity, command, or child step named `step` with `kind`. A command that failed as `Exhausted` or `DeadlineExceeded` is stored as `OutcomeUnknown`, as the actor stores it. The body sees `WorkflowStepFailedException`.

Parameters

NameTypeDescription
stepstring
errorexn
kindErrorKind

Returns

unit

Restart

this.Restart
Member
Replays the journal into a new run of the body, as the process does after it stops. Steps with a stored outcome are not run again; a step that was waiting waits again.

Returns

unit

Resume

this.Resume
Member
Resumes a faulted instance at the step whose failure faulted it, as `Resume` does for a registered workflow: the body replays its stored steps and that step waits again for the test's outcome. Raises `InvalidOperationException` with the reason when the instance cannot resume: it has not faulted, the body threw its own exception, or it ran steps after the failure.

Returns

unit

Signal

this.Signal
Member
Stores a signal, as `Workflows.signal` does. A wait for it takes it, now or when it starts. Raises `InvalidOperationException` when the instance has ended.

Parameters

NameTypeDescription
namestring
value'T

Returns

unit

StartAgain

this.StartAgain
Member
Starts a new run with `input`, as a start with `WorkflowIdReuse.AfterFailure` does: only when the instance faulted or was cancelled. Otherwise it stores nothing and reports the instance, as `AlreadyStarted`. The new run replays none of the earlier runs' records.

Parameters

NameTypeDescription
input'Input

Returns

StartResult

Summary

this.Summary
Member
One line per stored record, such as `"scheduled 0 price"` or `"completed 0 price"`: the step's path and name. Step values are in `Journal`.

Returns

IReadOnlyList<string>

Waiting

this.Waiting
Member
The steps the body waits on, in the order they started.

Returns

IReadOnlyList<WaitingStep>

Outcome

this.Outcome
Member
How the instance ended, or `None` while it runs or is parked.

Returns

WorkflowOutcome<'Result> option

Now

this.Now
Member
The time the test runs at. It starts at the time given to `Start` and moves with `Advance`.

Returns

DateTime

Status

this.Status
Member
Where the instance is, as `Status` reports it for a registered workflow.

Returns

WorkflowStatus

Id

this.Id
Member
The instance's ID, `test`. It is part of a child workflow's ID.

Returns

string

Journal

this.Journal
Member
Every record the instance stored, in journal order.

Returns

IReadOnlyList<WorkflowRecord>

Result

this.Result
Member
The body's result. Raises `WorkflowFaultedException` or `WorkflowCancelledException` when the instance ended otherwise, and `InvalidOperationException` while it has not ended.

Returns

'Result

Name

this.Name
Member
The workflow's name.

Returns

string